// app\service\serviceRegister.js
'use strict';

const Service = require('egg').Service;

class ServiceRegisterService extends Service {
  async postRegisterData(data) {
    let username = await this.app.mysql.get('user', { username: data.username });
    let phone = await this.app.mysql.get('user', { phone: data.phone });
    if (username) {
      return { code: 0, message: '用户名已存在' };
    }

    if (phone) {
      return { code: 0, message: '电话号已存在' };
    }
    const result = await this.app.mysql.insert('user'
      , {
        ...data
      }
    )
    return { code: 1, result }
  }
}

module.exports = ServiceRegisterService;
